//
//  IweSellerController.swift
//  eemall
//
//  Created by zhuxietong on 2018/9/13.
//  Copyright © 2018年 zhuxietong. All rights reserved.
//

import UIKit
import soapp
import AsyncDisplayKit
import Eelay
extension IweSellerController{
    class MenuNode: SellerFilterMenuNode {
        override func createMenu() -> EeFilterMenu {
            let menu = EeFilterMenu()
            
            
            let item1 = FilterOrder()
            item1.button.ui.ncolor(hex: "#070707").ntitle(title: "最新".loc).nimage(UIImage(named: "shangcheng_zuixing")?.rt_tintedImage(with: UIColor(shex: "#999"))).simage(UIImage(named: "shangcheng_zuixing")?.rt_tintedImage(with: UIColor(shex: "#999"))).scolor(hex: "#999").ncolor(hex: "#999").font(size: 13).imagePosition(.left)
            item1.asc = ("最新".loc,"createtime","asc",nil)
            
            let item2 = FilterOrder()
            item2.button.ui.ncolor(hex: "#070707").ntitle(title: "热度".loc).nimage(UIImage(named: "shop_order_n")).simage(UIImage(named: "shop_order_s")).scolor(hex: "#999").ncolor(hex: "#999").font(size: 13).imagePosition(.right)
            item2.asc = ("热度".loc,"sales","asc",nil)
            //        item2.desc = ("热度  ","time_deliver","-",nil)
            
            
            let item3 = FilterOrder()
            item3.button.ui.ncolor(hex: "#070707").ntitle(title: "价格".loc).nimage(UIImage(named: "lplb_xiala")).scolor(hex: "#999").ncolor(hex: "#999").font(size: 13).imagePosition(.right)
            item3.asc = ("价格".loc,"productprice","asc",UIImage(named: "sc_px"))
            item3.desc = ("价格".loc,"productprice","desc",UIImage(named: "sc_px2"))
            
            let item4 = FilterOption()
            item4.filterKey = "type_price"
            item4.button.ui.ntitle(title: "\("分类".loc)  ").stitle(title: "\("分类".loc)  ").nimage(UIImage(named: "sc_fl")).simage(UIImage(named: "sc_fl_s")).scolor(hex: "#000").ncolor(hex: "#999").font(size: 13).imagePosition(.right)
            
            let selector = GoodsSellerCateSelector()
            let ctr = self.mo.controller as? IweSellerController
            selector.sellerID = ctr?.mo.model["id",""]
            item4.filterSelector = .push(selector)
            
            menu.cellType = EeSearchController.MenuCell.self
            item1.itemWidth = Swidth/4.0
            item2.itemWidth = Swidth/4.0
            item3.itemWidth = Swidth/4.0
            item4.itemWidth = Swidth/4.0
            
            menu.collectionViewConfig = {
                cv in
                if let flow = cv.collectionViewLayout as? UICollectionViewFlowLayout
                {
                    flow.minimumInteritemSpacing = 0
                    flow.minimumLineSpacing = 0
                }
            }
            
            menu.items = [item1,item2,item3,item4]
            menu.observerFilter = {info in
                ctr?.filterValues = info
            }
            
            menu.controller = ctr
            menu.backgroundColor = UIColor(shex: "#fff")
            menu.frame = CGRect(x: 0, y: 0, width: Swidth, height: menu.menu_height)
            return menu
        }
    }
}

open class IweSellerController: ShoppingSellerCtr {
    
    override open var selector: TP.selector{
        get{
            let sel:TP.selector = [
                "cellID<header>":IweHeadNode.self,
                "cellID<empty>":EmptyCell.self,
                "header<YES>":MenuNode.self,
                ] + Goods.cellSelector
            return sel
        }
    }
    
    open override func viewDidLoad() {
        super.viewDidLoad()
        flowLayout.sectionHeadersPinToVisibleBounds = true
        ShoppingSellerCtr.top_height = 292.co
        collectionNode.registerSupplementaryNode(ofKind: UICollectionView.elementKindSectionHeader)

    }
   
  
    override open func willPlayupPageSection() {
        
        let list = DataNode.path(node: page_load_section, collectionNode.model, value: NSMutableArray())
        if list.count <= 0{
            collectionNode.model["section1"] = NSMutableArray()
            collectionNode.model["section2"] = [["cellID":"empty"]].mutable_array
        }else{
            collectionNode.model["section2"] = NSMutableArray()
        }
    }
    
    deinit {
        
    }
}



extension IweSellerController{
    
    class IweHeadNode: SellerHeadNode {
        override var HeaderType: ShoppingSellerCtr.BaseSellerHeader.Type{
            return IweSellerHeader.self
        }
    }
    
    class IweSellerHeader: BaseSellerHeader {
        
        
        open override func buildStrech() {
            self.backgroundColor = UIColor._background
            
            self.eelay = [
                [containerView,[ee.L.R.B]],
            ]
            
            self.heightLayoutConstraint = NSLayoutConstraint(item: containerView, attribute:.height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 1, constant: self.miniHeigth)
            self.addConstraint(heightLayoutConstraint)
            containerView.eelay = [
                [imageV,[ee.T.L.B.R]],
            ]
            containerView.clipsToBounds = false
        }
        
        
        
        override open func mo_model_reload() {
//            print("+++++OOOOOO",mo.model)
            if !isLoad{
                buildStrech()
                isLoad = true
            }
            imageV.img_url = mo.model["banner","0"]
        }
        

    }

   
    
}

